package com.foreveross.proxyip.entity;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import com.foreveross.proxyip.core.redis.AbstractStoreBean;
@SuppressWarnings({"unchecked","rawtypes"})
public class ProxyIpBean extends  AbstractStoreBean  {
//	public final static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7723276375671355736L;

	
//	private Long timeout = null;

	private String id;


	private Date createTime;

	private String area;

	private String ip;


	private Date lastTime;

	private Integer port;

	private Integer responseTime;
	
	private String retrieveChannel;

	private Date retrieveTime;
	@SuppressWarnings("unused")
	private String retrieveTimeStr ;
	
	private String source ;
	
	private Integer speedGrade;
	
	/*******该ip不能连接的渠道url，该属性公共池才能用********/
	private Set<String> refuseChannel = new HashSet<String>();
	/*******所在	池(包括公共池)验证的时间********/
	private Map<String,Long> channelVliTime = new HashMap();
	/*******所在	池(包括公共池)使用次数********/
	
	private Map<String,Integer> channelUseCount = new HashMap();
	/*******所在	池(包括公共池)进去的时间********/
	private Map<String,Long> ip2ChannelTime = new HashMap<String, Long>();
	/*******在所在渠道池离开的时间********/
	//private Map<String,Long> ipOutChannelTime = new HashMap<String,Long>();
	
	//状态//0 not use ,1 is useing(使用等级一般) 3 is delete, 4为比较优秀等级（延时性）,5为最优IP
	private Integer state;
	
//	private int usedCount  = 0;//公共池ip使用次数

	public ProxyIpBean() {
	}
	


	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}


	public String getArea() {
		return this.area;
	}

	public void setArea(String area) {
		this.area = area;
	}
	
	public String getCompletionIP() {
		return getIp() + ":" + getPort();
	}

	public String getIp() {
		return this.ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Date getLastTime() {
		return this.lastTime;
	}

	public void setLastTime(Date lastTime) {
		this.lastTime = lastTime;
	}

	public Integer getPort() {
		return this.port;
	}

	public void setPort(Integer port) {
		this.port = port;
	}

	public Integer getResponseTime() {
		return this.responseTime;
	}

	public void setResponseTime(Integer responseTime) {
		this.responseTime = responseTime;
	}

	public Integer getState() {
		return this.state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

//	public int getUsedCount() {
//		return usedCount;
//	}
//
//	public void setUsedCount(int usedCount) {
//		this.usedCount = usedCount;
//	}

	public String getRetrieveChannel() {
		return retrieveChannel;
	}

	public void setRetrieveChannel(String retrieveChannel) {
		this.retrieveChannel = retrieveChannel;
	}

	public Date getRetrieveTime() {
		return retrieveTime;
	}


	public void setRetrieveTime(Date retrieveTime) {
		this.retrieveTime = retrieveTime;
	}
	
	

	public Map<String, Integer> getChannelUseCount() {
		return channelUseCount;
	}



	public void setChannelUseCount(Map<String, Integer> channelUseCount) {
		this.channelUseCount = channelUseCount;
	}



	public String getSource() {
		return source;
	}



	public void setSource(String source) {
		this.source = source;
	}



	public Integer getSpeedGrade() {
		return speedGrade;
	}



	public void setSpeedGrade(Integer speedGrade) {
		this.speedGrade = speedGrade;
	}



	/**
	 * 根据该对象属性获取一个数据库持久类对象
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	public IpStoreEntity toIpStoreEntity() throws IllegalAccessException, InvocationTargetException{
		IpStoreEntity dest = new IpStoreEntity();
		dest.setCreateTime(this.getCreateTime());
		dest.setArea(this.getArea());
		dest.setIp(ip);
		dest.setLastTime(lastTime);
		dest.setPort(port);
		dest.setResponseTime(responseTime);
		dest.setState(state);
		dest.setSource(source);
		return dest;
	}



	public IpStoreTmpEntity toIpStoreTmpEntity() throws IllegalAccessException, InvocationTargetException{
		IpStoreTmpEntity dest = new IpStoreTmpEntity();
		dest.setCreateTime(this.getCreateTime());
		dest.setArea(this.getArea());
		dest.setIp(ip);
		dest.setLastTime(lastTime);
		dest.setPort(port);
		dest.setResponseTime(responseTime);
		dest.setState(state);
		dest.setId(UUID.randomUUID().toString().replace("-", ""));
		dest.setSource(source);
		return dest;
	}

	
	/**
	 * 根据该对象属性获取一个数据库持久类对象
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	public HistoryIpEntity toHistoryIpEntity() throws IllegalAccessException, InvocationTargetException{
		HistoryIpEntity dest = new HistoryIpEntity();
		dest.setArea(area);
		dest.setCreateTime(createTime);
		dest.setIp(ip);
		dest.setPort(port);
		dest.setResponseTime(responseTime);
		dest.setRetrieveChannel(retrieveChannel);
		dest.setRetrieveTime(retrieveTime);
		dest.setState(state);
		dest.setSource(source);
		return dest;
	}
	
	
	/**
	 * 根据该对象属性获取一个数据库持久类对象
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	public RetrieveIpEntity toRetrieveIpEntity() throws IllegalAccessException, InvocationTargetException{
		RetrieveIpEntity dest = new RetrieveIpEntity();
		dest.setArea(area);
		dest.setCreateTime(createTime);
		dest.setIp(ip);
		dest.setPort(port);
		dest.setResponseTime(responseTime);
		dest.setRetrieveChannel(retrieveChannel);
		dest.setRetrieveTime(retrieveTime);
		dest.setState(state);
		dest.setSource(source);
		return dest;
	}



	public Set getRefuseChannel() {
		return refuseChannel;
	}


	public Map<String, Long> getChannelVliTime() {
		return channelVliTime;
	}



	public void setChannelVliTime(Map<String, Long> channelVliTime) {
		this.channelVliTime = channelVliTime;
	}



	public String getRetrieveTimeStr() {
		return generateDateStr(retrieveTime);
	}



	public Map<String, Long> getIp2ChannelTime() {
		return ip2ChannelTime;
	}



//	public Map<String, Long> getIpOutChannelTime() {
//		return ipOutChannelTime;
//	}
//
//
//
//	public void setIpOutChannelTime(Map<String, Long> ipOutChannelTime) {
//		this.ipOutChannelTime = ipOutChannelTime;
//	}



	public void setIp2ChannelTime(Map<String, Long> ip2ChannelTime) {
		this.ip2ChannelTime = ip2ChannelTime;
	}



	public void setRefuseChannel(Set<String> refuseChannel) {
		this.refuseChannel = refuseChannel;
	}
	

	public void setRetrieveTimeStr(String retrieveTimeStr) {
		this.retrieveTimeStr = retrieveTimeStr;
	}
	private String generateDateStr(Date date){
		return date==null?"":com.foreveross.proxyip.infra.utils.DateUtils.DATE_FMT_CN_BARS_YMD_HMS.format(date);
	}

}